package com.ztom.test

import com.ztom.beans.factory.DefaultListableBeanFactory
import com.ztom.beans.factory.support.extenssions.getBean
import com.ztom.beans.factory.support.reader.xml.XmlBeanDefinitionReader
import com.ztom.test.bean.Car
import com.ztom.test.bean.Person
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

/**
 * @author ZhangTao
 */
class Test05XmlDefineBean {

    @Test
    fun test() {
        val beanFactory = DefaultListableBeanFactory()
        val reader = XmlBeanDefinitionReader(beanFactory)
        reader.loadBeanDefinitions("classpath:spring-05-xml-define-bean.xml")

        val person = beanFactory.getBean<Person>()
        println(person)
        assertEquals(person.name, "无羡")
        assertEquals(person.age, 18)
        assertEquals(person.car?.brand, "BMW")

        val car = beanFactory.getBean<Car>()
        println(car)
        assertEquals(car.brand, "BMW")
    }
}